<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="com.iris.egrant.service.ServiceUtils"%>
<%@page import="com.iris.egrant.web.struts2.Struts2Utils"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common-app/taglibs.jsp"%>
<%@ include file="/common/meta.jsp"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title></title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	
	<script type="text/javascript" src="${res}/js/proposal/irisPrpPrepare.js"></script>
	<script type="text/javascript" src="${res_app}/js/app/proposal/irisPrpPrepare.js"></script>
	<script type="text/javascript" src="${res}/js/validate/irisvalidator.js"></script>
	<script type="text/javascript" src="${res}/js/autodisckey/autodisckey.js"></script>
	<script type="text/javascript" src="${res_app}/js/app/product.js"></script>
	 <script type="text/javascript">
	 
	 $(document).ready(function(){  //textarea 取值
		 var opFlag = "${param.flag }";
		 if (opFlag == "edit"){
			 var parentTr= parent.$("#tblExecuteProducts").find(":radio:checked").parents("tr");
			 if (parentTr.length == 0){  //
				 return ;
			 }
			 $("textarea").each(function(){
				 $(this).val(parentTr.find("textarea[name$='"+$(this).attr("name")+"']").val());
			 });
			 //$("textarea[name='achievement/summary1']").val(parentTr.find("textarea[name$='achievement/summary1']").val());
		  }
	 }); 
	 
	 
  	
  		//点击保存
	  function save()
		{
			var parentTable= parent.$("#tblExecuteProducts");
			bfSave();
			SavePersonsData();
			ValData();
			if(!valResult()){
				irisValShowMsg($("#saveProduct"));
				return false;
			}
			var url = document.URL;
			if(IsAdd())
			{
				addNewRowDeal(parentTable);
				addflag="1";
				parentTable.find("tr:last").find(":radio").attr("checked","checked");
			} 
			dataSave();
			if(confirm("保存成功，是否返回申请书页面"))parent.tb_remove();
			selectRadio = parentTable.find(":radio:checked");	//父页面选中的单选框
			selectTr = selectRadio.parents("tr");				//父页面选中的行
		}
  		
	  function IsAdd()
		{
			if(addflag=="1") return false;
			var url = document.URL;
			if(url.indexOf("flag=add")>0)
				return true;
			else
				return false;
		}
	  
	  //textarae处理
	  function bfSave(){
			$("textarea").each(function(){
			var val=$(this).val();
			val = val.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g,"<br/>").replace(/\s/g,"&nbsp;").replace(/"/g,"&quot;");
			$("input[name='"+$(this).attr('name')+"_hidden']").val(val);
			}); 
		}

	  	//填写检查
	  function ValData() 
		{	
		   if(!irisJqValEmpty2($("#basic01"),"大型设备购置申请表请完整填写"))
		   {
				validate($("#basic01"),"大型设备购置申请表");
			}
		   validate($("#basic02"),"大型设备购置申请表");
			
		}
	  
	  //校验方法重写
	  function validateByTabRow(obj, title, rowNum) {
			 
			 if(obj.attr("id") =='tblProducts'){
					
				 if ((obj.find("tr").length - 4) < rowNum)
						irisValaddMsg(messageTip.rowNum.replace("[name]", title).replace(
								"[num]", rowNum));
					}else if(obj.attr("id") =='tblProductsResearch'){
						if ((obj.find("tr").length - 10) < rowNum)
							irisValaddMsg(messageTip.rowNum.replace("[name]", title).replace(
									"[num]", rowNum));
					}else{
						if ((obj.find("tr").length - 2) < rowNum)
							irisValaddMsg(messageTip.rowNum.replace("[name]", title).replace(
									"[num]", rowNum));
					}
			 
			var childStr=">tr";
			var minus_cnt =1;
			var start_idx =2;
			if($("#"+obj.attr("id")+">tbody").length>0){
				childStr=">tbody>tr";
			}
			if($("#"+obj.attr("id")+">thead").length>0){
				minus_cnt= 0;
				start_idx =1;
			}
			$("#"+obj.attr("id")+childStr).each(
					function(index) {

						if (index >= start_idx) {
								rtitle = messageTip.rowIndex.replace("[name]", title)
								.replace("[index]", index - minus_cnt);
							validate($(this), rtitle);
						}
					});
		}
		
		
		//保存xml
		function SavePersonsData()
		{	
			var strXmlData = prePareXmlDataStand($("#dojoTabParent"),null);	
			 strXmlData = "<?xml version='1.0' encoding='UTF-8'?><data>" + strXmlData + "</data>";
			$("input[name='xmldata']").val(strXmlData);			
		}
		
		function dataSave()
		{
			var parentTable = parent.$("#tblExecuteProducts");
			var seletedRow=parentTable.find(":radio[checked='checked']").parents("tr");
			
			$("input:not(:radio:button),textarea").each(function(){
				
				var id=$(this).attr("name");
				var parentObj=null;
				if(id==null || id=="")
					return true;
				//获得父页面的对象
				parentObj=seletedRow.find("[name$='/"+id+"']");
				if(parentObj!=null){
					if(parentObj.is("span")){
						parentObj.text($(this).val());	//将值写回父页面
					}
					else{
						parentObj.val($(this).val());
					}
				}
				
			});
		}
		
		
		
		//实现checkbox检查接口，告知initControl() 函数 ，此控件由标签生成，绑定值与赋值逻辑有差异
		/*
		*
		*/
		 function isTagCheckBox(name){
			if(name.indexOf("isleader")!=-1)
				return true;
			if(name.indexOf("ismember")!=-1)
				return true;
			if(name.indexOf("isgetstartfund")!=-1)
				return true;
			
			return false;
		}
		
		
		
		
		
		/*****************表格操作方法重写********************/
		 /**
		  * 限制Table行数 （重写）
		  * @param tableId表格id
		  * @param max最大行数
		  * @returns {Boolean}
		  */
		 function checkTabLimitRewrite(tableId,max,message)
		 {
		 	var maxLinNum=$("#"+tableId+">tbody>tr").length-1;
		 	
		 		if(maxLinNum>=max)
		 		{
		 			scmWarn(message);
		 			return false;
		 		}
		 	return true;
		 }
		  
		  /**
		   * 增加一行
		   * @param tableId表格Id
		   * @param radioId
		   * @param nNewRowPosition
		   * @param startRowIndex
		   */
		   function addNewRowDeal(table)
		  {
		  	if(table.attr("id")=='tblExecuteProducts'){
		  		var maxLinNum=table.find("tr").length-2;;//获得行数，减去表头和隐藏行
		  		var lineNum=""+(maxLinNum+1);
		  		
		  		var addHtml=table.find("tr")[1].innerHTML;//获得隐藏行的html,查找第二行
		  		addHtml=addHtml.replace(/\[index\]/g,lineNum);
		  		lineNum = (parseInt(lineNum, 10)-1).toString();//2011.12.13 行下标比行号小1(隐藏行下标[0]，第一行下标[00])
		  		if (lineNum.length==1)//如果是个位数，前面补0
		  			lineNum="0"+lineNum;
		  		addHtml=addHtml.replace(/\[0\]/g,"["+lineNum+"]");//替换html中行号
		  		addHtml=addHtml.replace(/\|/g,"/");//替换html中节点/的代替符"|"
		  		table.append("<tr>"+addHtml+"</tr>");//将html增加到最后
		  	}else{
		  		var maxLinNum=$("#"+table.attr("id")+">tbody>tr").length-1;//获得行数，减去表头和隐藏行
		  		var lineNum=""+(maxLinNum+1);
		  		
		  		var addHtml=table.find("tr")[1].innerHTML;//获得隐藏行的html,查找第二行
		  		addHtml=addHtml.replace(/\[index\]/g,lineNum);
		  		addHtml=addHtml.replace(/\[index\-1\]/g,maxLinNum);
		  		lineNum = (parseInt(lineNum, 10)-1).toString();//2011.12.13 行下标比行号小1(隐藏行下标[0]，第一行下标[00])
		  		if (lineNum.length==1)//如果是个位数，前面补0
		  			lineNum="0"+lineNum;
		  		addHtml=addHtml.replace(/\[0\]/g,"["+lineNum+"]");//替换html中行号
		  		addHtml=addHtml.replace(/\|/g,"/");//替换html中节点/的代替符"|"
		  		
		  		table.append("<tr >"+addHtml+"</tr>");//将html增加到最后
		  	}
		  } 
		  
		  
		 
  
  </script>
	<script type="text/javascript">
		var parenttbl = "tblExecuteProducts";
		var parentsel = "selExecuteProducts";
		var parentTable = parent.$("#tblExecuteProducts");
		var addflag="";
		var selectRadio = $();									//父页面选中的单选框
		var selectTr = $();		
	
		
		
		//初始化样式
		$(document).ready(function(){
			setTimeout("initControl('dojoTabParent')",1000);
			$("table.t_css").not("[id='finances']").not("[id='budget1']").each(function(){
				$(this).find("tr").not($(".cbTable").find("tr")).each(function(index){
					if(index%2==0)
						$(this).removeClass("li_1").addClass("li_2");
					else
						$(this).removeClass("li_2").addClass("li_1");
				});
			});
			$("table").not(".cbTable").addClass("table01"); 
		    $('div').find("[id^='checkbox_dyn_']").find("tr").removeClass("li_1").removeClass("li_2");
		    $('div').find("[id^='checkbox_dyn_']").find("td").css("border",'0px solid');
		    $('.buttonTable').removeClass("table01").css("border",'0px solid');
		    
			<c:if test="${param.flag=='view'}">
			//以下是查看页面
			$(".money").parent().attr("align","center");	//金额居中显示
			
			DisabledAll("input");
			DisabledAll("select");
			DisabledAll("textarea");
			$(".datepick-trigger").css("display","none");
			$('.color_red').text('');
			$(".button").remove();
			$(".tb_button").remove();
			$(".inputSelectButton").remove();
			$("img").not("#orgphotoImg").remove();
			</c:if> 
		});
		
		//查看 disabled wk del 2014-5-5
		function DisabledAll2(tagName){
			$(tagName).not(".button_01").attr("disabled",true);
		}
		
		//覆盖，替换checkbox
		function DisabledAll(tagName)
		{
			 var allObj = $(tagName);
			 	
			 var len=allObj.length;
			for(var i = len-1; i >=0; i--)
			{
									
				var tag=allObj[i];
				//parentElement 和 parentNode一样,但parentNode是W3C标准的parentElement 只在IE中可用
				//var p = tag.parentElement;
				var p = tag.parentNode;
				if(!p) p = document;

				if(/\r(\n)?/g.test(tag.value)==true&&tagName=='textarea')
				{
					newTag = getSpan(tag.value.replace(/\r(\n)?/g,"<br>"));
					p.replaceChild(newTag,tag);
				}
				else if(tagName=="select")
				{
						newTag = getSpan(tag.options[tag.selectedIndex].innerText);
						p.replaceChild(newTag,tag);
				} 
				else
				{
					if(tagName.toLowerCase()=='textarea')
					{
						newTag = getSpan(tag.value);
						p.replaceChild(newTag,tag);	
					}
					else if(tagName.toLowerCase()=='input'&&tag.type&&tag.type=='checkbox') {
						newTag = document.createElement("span");
						if(tag.checked == true)
							newTag.className="tu_biao1";
						else
							newTag.className="tu_biao2";
						p.replaceChild(newTag,tag);	
					}
					else if(tagName.toLowerCase()=='input'&&tag.type&&tag.type!='button'&&tag.type!='hidden')
					{
						if(tag.type=='radio')
						{
							p.parentNode.removeChild(p);
						}
						else
						{
							newTag = getSpan(tag.value);
							p.replaceChild(newTag,tag);
						}
						
					}
					
				}
			}
		}
	</script>
  </head>

  <body >
   <c:set var="xmlStr">
   		<%=ServiceUtils.decodeFromDes3(Struts2Utils.getSession().getAttribute("encryptData").toString()) %>
   </c:set>
   <% Struts2Utils.getSession().removeAttribute("encryptData");%>
  	<x:parse xml="${xmlStr}" var="xmlData"/> 
  		<div class="dojoTabPaneWrapperDiy" id="dojoTabParent" >
  			 <div style="position: relative;">
  				<div id="tabnav">
					<ul>
						<li class="down"><a href="###"><span>大型设备购置申请表</span></a></li>
					</ul>
		       </div>	
				<div id="fragment-tab1" class="tab_box" label="大型设备购置申请表" >
				<div class="t_bar2"><span class="color_red">*</span>大型设备购置申请表（单位：万元）</div>
						<table class="t_css table01" width="100%" border="0" cellpadding="0" id="basic01" cellspacing="0">
							<col width="20%">
							<col width="30%">
							<col width="20%">
							<col width="30%">
							<tr>
								<td align="right">设备名称：</td>
								<td >
									<input name="basicinfo/fac_name" style="width: 80%;" maxlength="100" class="input_css  maxlength:100" value="<x:out  select="$xmlData/data/basicinfo/fac_name"/>"/>
								</td>
								<td align="right">设备型号：</td>
								<td >
									<input name="basicinfo/fac_model" style="width: 80%;" maxlength="100" class="input_css  maxlength:100" value="<x:out  select="$xmlData/data/basicinfo/fac_model"/>"/>
								</td>
							</tr>
							<tr>
								<td align="right">生产国别：</td>
								<td >
									<input name="basicinfo/country" style="width: 80%;" class="input_css  maxlength:100" value="<x:out  select="$xmlData/data/basicinfo/country"/>"/>
								</td>
								<td align="right">生产厂家：</td>
								<td >
									<input name="basicinfo/factory" style="width: 80%;"  class="input_css  maxlength:100" value="<x:out  select="$xmlData/data/basicinfo/factory"/>"/>
								</td>
							</tr>
							<tr>
								<td align="right">技术性能指标：</td>
								<td colspan="3">
									<input name="basicinfo/indicators" style="width: 93%;" class="input_css  maxlength:100"  maxlength="100" value="<x:out  select="$xmlData/data/basicinfo/indicators"/>"/>
								</td>
							</tr>
							<tr>
								<td align="right">设备数量：</td>
								<td >
									<input name="basicinfo/fac_num" style="width: 80%;text-align: right;" onfocus="InitInput.setNumber(this,9,0,0);" class="input_css money  maxlength:100" value="<x:out  select="$xmlData/data/basicinfo/fac_num"/>"/>
								</td>
								<td align="right">设备总价：</td>
								<td >
									<input name="basicinfo/fac_total" style="width: 80%;text-align: right;" onfocus="InitInput.setNumber(this,7,4,2);" class="input_css money maxlength:100" value="<x:out  select="$xmlData/data/basicinfo/fac_total"/>"/>
								</td>
							</tr>
							<tr>
								<td align="right">申请财政资金：</td>
								<td >
									<input name="basicinfo/app_fund" style="width: 80%;text-align: right;" onfocus="InitInput.setNumber(this,7,4,2);" class="input_css money maxlength:100" value="<x:out  select="$xmlData/data/basicinfo/app_fund"/>"/>
								</td>
								<td align="right">其它渠道资金：</td>
								<td >
									<input name="basicinfo/other_fund" style="width: 80%;text-align: right;" onfocus="InitInput.setNumber(this,7,4,2);" class="input_css money maxlength:100" value="<x:out  select="$xmlData/data/basicinfo/other_fund"/>"/>
								</td>
							</tr>
							<tr>
								<td align="right">设备安置单位：</td>
								<td colspan="3">
									<input name="basicinfo/placement_org" style="width: 93%;" class="input_css  maxlength:100" maxlength="100" value="<x:out  select="$xmlData/data/basicinfo/placement_org"/>"/>
								</td>
							</tr>
							
							<tr>
								<td align="right">设备共享范围：</td>
								<td colspan="3" style="height: auto;">
									<c:set  var="shared_range_value"><x:out  select="$xmlData/data/basicinfo/shared_range_value"/></c:set>
									<cpt:checkbox key="shared_range" repeatColumn="2" name="shared_range" value="${shared_range_value }" width="160px;"></cpt:checkbox>
									<input type="hidden" name="basicinfo/shared_range_value" class="required" label="设备共享范围" value="${shared_range_value }"/>
									<input type="hidden" name="basicinfo/shared_range_name" value="<x:out  select="$xmlData/data/basicinfo/shared_range_name"/>"/>
								</td> 
							</tr>
					</table>
				<table class="t_css table01" width="100%" border="0" cellpadding="0" id="basic02" cellspacing="0"  style=" word-break: break-all; word-wrap: break-word;table-layout:fixed;">
			      <tr class="li_1" style="height: auto;">
			          <td align="left" colspan="4">购置该设备的必要性：（包括设备安置单位的现有设备条件及与该设备的关系、设备使用率、与国内单位共享的可能性等，限300字）</td>
			      </tr>
			      <tr class="li_2" style="height: auto;">
			          <td colspan="4">
						<textarea rows="5" cols="110"  class="input_textarea required  maxlength:300"   name='proposal/fund/summary1'  label="购置该设备的必要性" ><c:if test="${param.flag=='view'}"><pre></c:if><x:out select="$xmlData/data/proposal/fund/summary1"/><c:if test="${param.flag=='view'}"></pre></c:if></textarea>
					   <input type='hidden' name='proposal/fund/summary1_hidden' id='proposal/fund/summary1_hidden' value=''>
						</td>
			      </tr>
			      <tr class="li_1" style="height: auto;">
			          <td align="left" colspan="4">购置该设备的经济合理性：（包括设备价格、设备在同类设备中的档次及其理由、生产国别、从国外进口的理由等，限300字）</td>
			      </tr>
			      <tr class="li_2" style="height: auto;">
			          <td colspan="4">
						<textarea rows="5" cols="110" name='proposal/fund/summary2' class="input_textarea required  maxlength:300"   label="购置该设备的经济合理性"><c:if test="${param.flag=='view'}"><pre></c:if><x:out select="$xmlData/data/proposal/fund/summary2"/><c:if test="${param.flag=='view'}"></pre></c:if></textarea>
				        <input type='hidden' name='proposal/fund/summary2_hidden' id='proposal/fund/summary2_hidden' value=''>
				      </td>
			      </tr>
			       <tr class="li_1" style="height: auto;">
			          <td align="left" colspan="4">该类设备的省内分布情况：（单位名称、所在地、设备型号、设备共享的可能性，限300字）</td>
			      </tr>
			      <tr class="li_2" style="height: auto;">
			          <td colspan="4">
						<textarea rows="5" cols="110" name='proposal/fund/summary3' class="input_textarea required  maxlength:300"   label="该类设备的省内分布情况"><c:if test="${param.flag=='view'}"><pre></c:if><x:out select="$xmlData/data/proposal/fund/summary3"/><c:if test="${param.flag=='view'}"></pre></c:if></textarea>
				        <input type='hidden' name='proposal/fund/summary3_hidden' id='proposal/fund/summary3_hidden' value=''>
				      </td>
			      </tr>
			      <tr class="li_1" style="height: auto;">
			          <td align="left" colspan="4">设备主要研究应用情况（限300字）</td>
			      </tr>
			      <tr class="li_2" style="height: auto;">
			          <td colspan="4">
						<textarea rows="5" cols="110" name='proposal/fund/summary4' class="input_textarea required  maxlength:300"   label="设备主要研究应用情况"><c:if test="${param.flag=='view'}"><pre></c:if><x:out select="$xmlData/data/proposal/fund/summary4"/><c:if test="${param.flag=='view'}"></pre></c:if></textarea>
				        <input type='hidden' name='proposal/fund/summary4_hidden' id='proposal/fund/summary4_hidden' value=''>
				      </td>
			      </tr>
			       <tr class="li_1" style="height: auto;">
			          <td align="left" colspan="4">设备主要厂家情况（必须提供至少2个厂家报价，限300字）</td>
			      </tr>
			      <tr class="li_2" style="height: auto;">
			          <td colspan="4">
						<textarea rows="5" cols="110" name='proposal/fund/summary5' class="input_textarea required  maxlength:300"   label="设备主要厂家情况"><c:if test="${param.flag=='view'}"><pre></c:if><x:out select="$xmlData/data/proposal/fund/summary5"/><c:if test="${param.flag=='view'}"></pre></c:if></textarea>
				        <input type='hidden' name='proposal/fund/summary5_hidden' id='proposal/fund/summary5_hidden' value=''>
				      </td>
			      </tr>
			    </table>
				
					<script type="text/javascript">
						showAllDateTag("bankOpinion");
					</script>
				</div>
			</div>
		</div>
		<table width="100%" align="center" class="buttonTable">
			<tr>
				<td align="center">
					<c:if test="${param.flag!='view'}">
					<input class="button_01" type="button" value=" 保 存 " id="saveProduct"
						onclick="save();">
					</c:if>
					<input class="button_01" type="button" value=" 取消 "
						onclick="parent.tb_remove();">
						<input type="hidden" value="" name="xmldata">
				</td>
			</tr>
		</table>
  </body>
  
  
  
  <script type="text/javascript">

  	//ie下置灰框高度调整
  	$(function () {
  		$("#fragment-tab1").find(":input[class*='gray']").css("height","20px");
  	});
		  
  	function loansDetailCount(){
		sumTotal('tblLoansDetail','amt','amt_total');
		sumTotal('tblLoansDetail','interest_reality','interest_reality_total');
		sumTotal('tblLoansDetail','interest_payed','interest_payed_total');
		sumTotal('tblLoansDetail','principle_payed','principle_payed_total');
		sumTotal('tblLoansDetail','interest_payed_base','interest_payed_base_total');
  	}
  
 	 // 对id="tableId"某表中，后缀名为sourceInputName所有求和，赋值给id="destInputId"的input
	  function sumTotal(tableId,sourceInputName,destInputId){
		  var sourceInputs = $("#"+tableId).find("input[name$='"+sourceInputName+"']");
		  var count = 0;
		  for ( var i = 0; i < sourceInputs.length; i++) {
		  	var fund = $(sourceInputs[i]).val();
		  	if (!$.isNumeric(fund))
		 	 fund = "0";
		 	 count = ((parseFloat(count)*10000 + parseFloat(fund)*10000)/10000).toFixed(4);
		  }
		  count = formatVal2(count);// 格式化金额
		 // alert(count);
		  //alert($("#" +destInputId));
		  $("#" +destInputId).val(count);
	  } 
  </script>
</html>

